﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CsharpTrainer.Model.Entities;
using PostDbNet;

namespace CsharpTrainer.Core.DAL
{
    public class CharacterListFunc : IFunction<AccountCharacter>
    {
        public IList<AccountCharacter> Query(string sql)
        {
            PostSqlUtil db = new PostSqlUtil("fr_gamedb_1");
            DataSet ds = db.GetDataSet(sql);
            AccountCharacter character = null;
            IList<AccountCharacter> characterList = null;
            if (ds.Tables[0].Rows.Count > 0)
            {
                characterList = new List<AccountCharacter>();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    character = new AccountCharacter();
                    character.CharacterName = ds.Tables[0].Rows[i]["charactername"].ToString();
                    character.CharacterId = ds.Tables[0].Rows[i]["characterid"].ToString();
                    character.LoginTime = Convert.ToDateTime(ds.Tables[0].Rows[i]["logintime"].ToString());
                    character.LoginIP = ds.Tables[0].Rows[i]["loginip"].ToString();
                    characterList.Add(character);
                }
            }

            return characterList;
        }

        public bool Execute(string sql)
        {
            return false;
        }
    }
}
